package com.winbomb.kingcard.base.anim.impl;

import com.winbomb.kingcard.Assets;
import com.winbomb.kingcard.IGameLogic;
import com.winbomb.kingcard.Pos;
import com.winbomb.kingcard.base.BattleState;
import com.winbomb.kingcard.base.GameLogic;
import com.winbomb.kingcard.base.anim.IPlayable;
import com.winbomb.kingcard.base.anim.SimpleAnimation;
import com.winbomb.kingcard.framework.Graphics;

public class AttackResultAnim implements IPlayable {

	private IGameLogic game;
	private Graphics g;
	private boolean isSucceed;

	private SimpleAnimation anim;

	/**
	 * 攻击结果的动画
	 * 
	 * @param game
	 * @param tgPos
	 *            目标位置
	 * @param isSucceed
	 *            是否攻击成功
	 */
	public AttackResultAnim(IGameLogic game, Pos tgPos, boolean isSucceed) {
		this.game = game;
		this.g = ((GameLogic) game).getRender().getGraphics();
		this.isSucceed = isSucceed;

		anim = new SimpleAnimation(tgPos);
		anim.setDuration(500);
		anim.setFrameInterval(50);
		anim.setFrameCount(10);
	}

	@Override
	public boolean play(float dt) {
		if (!anim.hasFinished()) {

			int frameNum = anim.getCurrFrame();
			int x = anim.getPos().x;
			int y = anim.getPos().y;
			g.drawPixmap(Assets.kill_miss, x, y, 50 * frameNum, (isSucceed) ? 0 : 60, 50, 60);

			anim.step(dt);
			return false;
		}

		game.setState(BattleState.FIGHT_START);
		return true;
	}

}
